/*
 mock 用户管理数据模拟
*/

import Mock from 'mockjs';
import { param2Obj } from '@/utils';

// 用户查询list
const userQueryList = [];
// list大小
const count = 100;

// 初始化用户查询list数据
for (let i = 0; i < count; i++) {
    userQueryList.push(Mock.mock({
      id:'1111111111111111111',
      loginName: '@increment',
      role: '@cname',
      loginPassword: '123456',
      name: '@cname',
      phone: '13610368174',
      email: '88888@qq.com',
      sex: 0,
      roleId: 'a175a8df9c5e40f982e2b89c2b62c27c',
      sessionExpireTime: 8888
    }));
}

// 新增用户,修改用户信息
const userMap = {
    addUser: {
        meta: {
            code: 200,
            message: ''
        },
        data: {}
    },
    updateUser: {
        meta: {
            code: 200,
            message: ''
        },
        data: {}
    },
    roles: {
        meta: {
            code: 200,
            message: ''
        },
        data: [
            { id:'a175a8df9c5e40f982e2b89c2b62c27c',name:'超级管理员' },
            { id:'db7087edb5084035bf77a5cfbd2ed640',name:'路人甲' }
        ]
    },
    deleteUser: {
        meta: {
            code: 200,
            message: 'success'
        },
        data: {}
    },
    getUserInfo: {
        meta: {
            code: 200,
            message: ''
        },
        data: {
            userId: '8888888888888888888888',
            loginName: 'admin',
            email: '65333@qq.com',
            phone: '13610368174',
            roleName: '超级管理员',
            rolePermission: '',
            isSuperAdmin: 1,
            userName: 'admin'
        }
    },
    testGetUserInfo: {
        meta: {
            code: 200,
            message: ''
        },
        data: {
            userId: '8888888888888888888888',
            loginName: 'admin',
            email: '65333@qq.com',
            phone: '13610368174',
            roleName: '超级管理员',
            rolePermission: '/document,/monitoring,/document/develop/index,/document/user/index,/monitoring/plateform/function,/monitoring/application/function,/monitoring/node/function,/diary/operation/index,',
            isSuperAdmin: 0,
            userName: 'admin'
        }
    }
}

export default {
    // 用户分页查询
    queryUserBase: config => {
        // 得到post的参数
        // const { page, pageSize, queryKey } = JSON.parse(config.body);
        const { page, pageSize, queryKey } = param2Obj(config.url);


        // 分页查询
        const pageList = userQueryList.filter((item, index) => index < pageSize * page && index >= pageSize * (page - 1));

        return {
            meta: {
                code: 200,
                message: ''
            },
            data: {
                total: userQueryList.length,
                items: pageList
            }
        }
    },
    // 新增用户
    addUser: () => {
        return userMap['addUser'];
    },
    // 修改用户
    updateUser: () => {
        return userMap['updateUser'];
    },
    getRoles: () => {
        return userMap['roles'];
    },
    // 删除用户信息
    deleteUser: () => {
        return userMap['deleteUser'];
    },
    // 获得登录用户的权限信息等
    getUserInfo: () => {
        return userMap['getUserInfo'];
        //return userMap['testGetUserInfo'];
    },
    // 获得登陆用户的团队信息
    getTeamCombobox: () => {
        return {
            meta: {
                code: 200,
                message: ''
            },
            data: [
                {id: '888888', nameCn: 'xx1团队', nameEn: 'ddd'},
                {id: '999999', nameCn: 'xx2团队', nameEn: 'dd'},
                {id: '777777', nameCn: 'xx3团队', nameEn: 'dddd'},
            ]
        }
    },
    getNamespaceCombobox: () => {
        return {
            meta: {
                code: 200,
                message: ''
            },
            data: [
                {id: '888888', kubeName: 'dev01', typeName: '生产坏境'},
                {id: '999999', kubeName: 'pro01', typeName: '开发坏境'},
                {id: '777777', kubeName: 'test01', typeName: '测试坏境'},
            ]
        }
    }
}
